<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

    </style>
</head>

<body>

    <div id="box">


    </div>


    <script src="./js/react.js"></script>
    <script src="./js/react-dom.js"></script>
    <script src="./js/prop-types.js"></script>
    <script src="./js/babel.min.js"></script>

    <script type="text/babel">

        // 注意：
        // 1、setState的参数是json对象
        // 2、json对象只能写根属性。
        // 3、setState内部做的浅合并：只能替换根属性

        class Book extends React.Component {

            constructor() {
                super();
                this.state = {
                    person: {
                        name: "周文静",
                        age: 16
                    }
                }
            }

            addAge=()=>{
                this.setState({
                    person:{
                        ...this.state.person,
                        age:this.state.person.age+1
                    }
                })
            }

            render = () => {
                return (
                    <div>
                        <p>姓名：{this.state.person.name}</p>
                        <p>年龄：{this.state.person.age}</p>

                        <input type="button" value="长大" onClick={this.addAge} />

                    </div>
                )
            }
        }

        let price = 12.5;

        const root = (<div>
            <h1>组件：</h1>
            <Book author="李泽辉" price={price} />
        </div>
        );

        ReactDOM.render(root, document.getElementById("box"));


    </script>
</body>

</html>